//
//  PickupCodeHeadView.m
//  ProjectforHDX
//
//  Created by yinda on 2018/8/7.
//  Copyright © 2018年 H.DX. All rights reserved.
//

#import "PickupCodeHeadView.h"
#import "WCheckgoodsCell.h"
#import "PlateModel.h"
#import "PickupModel.h"

@interface PickupCodeHeadView()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation PickupCodeHeadView

- (instancetype)initWithFrame:(CGRect)frame{
   self =  [super initWithFrame:frame];
    if (self) {
        [self setView];
    }
    return self;
}

- (void)setView{
    UITableView *tableView = [[UITableView alloc]init];
    self.tableView = tableView;
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.scrollEnabled = NO;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [tableView setFrame:CGRectMake(0, 40, SCREEN_WIDTH, self.height-40)];
    [self addSubview:tableView];
    
    WCheckgoodsTitleView *titleView = [[WCheckgoodsTitleView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40)];
    titleView.isCunOrQu = YES;
    [self addSubview:titleView];
}
- (void)setPlatesArr:(NSMutableArray *)platesArr{
    _platesArr = platesArr;
    [self.tableView reloadData];
}

#pragma -mark tableView datasource delegate
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    WCheckgoodsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WCheckgoodsCell"];
    if (!cell) {
        cell = [[WCheckgoodsCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"WCheckgoodsCell"
                ];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell setPlateModle:self.platesArr[indexPath.row]];
    
    UITapGestureRecognizer *plateNoRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(touchPlateNo:)];
    cell.plateNo.tag = 1000 + indexPath.row ;
    plateNoRecognizer.view.tag = cell.plateNo.tag;
    [cell.plateNo addGestureRecognizer:plateNoRecognizer];
    cell.plateNo.userInteractionEnabled = YES;
    
    UITapGestureRecognizer *plateSeriaRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(touchPlateSeria:)];
    cell.plateSeria.tag = 2000 + indexPath.row ;
    plateSeriaRecognizer.view.tag = cell.plateSeria.tag;
    [cell.plateSeria addGestureRecognizer:plateSeriaRecognizer];
    cell.plateSeria.userInteractionEnabled = YES;
    
    cell.plateNum.tag = 3000 + indexPath.row;
    cell.plateNum.textAlignment = NSTextAlignmentCenter;
    cell.plateNum.borderStyle = UITextBorderStyleNone;
    cell.plateNum.hidden = YES;
    return cell;
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (self.platesArr.count < 1) {
        [[BDHUD sharedManager] showNOneDataViewHUD:self.tableView top:60 title:[THMangerTool language:@"HUD.noOrderData"] onClick:^{
        }];
        
    }else{
        [[BDHUD sharedManager] dismissHUD:self.tableView];
    }
    
    
    return self.platesArr.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"当前是第 %ld 个cell",(long)indexPath.row);
    WCheckgoodsCell *cell = [[WCheckgoodsCell alloc]init];
    [cell setPlateModle:self.platesArr[indexPath.row]];
    return cell.height;;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIView *view = [UIView new];
    view.backgroundColor = [UIColor clearColor];
    [tableView setTableFooterView:view];
    
    if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [tableView setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [tableView setLayoutMargins:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}


@end
